package applications.away3d {
	import away3d.cameras.Camera3D;
	import away3d.containers.Scene3D;
	import away3d.lights.DirectionalLight3D;
	import core.SkeletonModeler;
	import display3d.away3d.ViewContainer3D;
	import flash.events.Event;
	import flash.geom.Vector3D;
	import jazztures.objects.Skeleton;
	import jazztures.plugins.away3d.Skeleton3D;

	[SWF(width=800, height=800, frameRate=30, backgroundColor=0x000000)]
	public class SkeletonModelerAway3D extends SkeletonModeler
	{
		private var camera:Camera3D;
		private var camera2:Camera3D;
		
		private var light:DirectionalLight3D;
		
		private var view:ViewContainer3D;
		private var view2:ViewContainer3D;
		
		protected var world:Scene3D;
		
		protected var skeleton3D:Skeleton3D;
				
		public function SkeletonModelerAway3D()
		{
			super();
		}
				
		override protected function build():void{
			super.build();
			world = new Scene3D();
			
			camera = new Camera3D();
			camera.z = -2000;
			camera.x = stage.stageWidth/4;
			camera.y = -stage.stageHeight/2;
			world.addChild(camera);
					
			view = new ViewContainer3D(stage.stageWidth/2, stage.stageHeight/2, camera, world);
			view.x = stage.stageWidth/2;
			addChild(view);
			
			camera2 = new Camera3D();			
			camera2.rotationY = 90;
			camera2.x = -2000;
			camera2.y = -stage.stageHeight/2;
			world.addChild(camera2);
			
			view2 = new ViewContainer3D(stage.stageWidth/2, stage.stageHeight/2, camera2, world);
			view2.x = stage.stageWidth/2;
			view2.y = stage.stageHeight/2;
			addChild(view2);
			
			light = new DirectionalLight3D();
			world.addLight(light);
			light.direction = new Vector3D(150,150,150);

			buildSkeleton();
			
			addEventListener(Event.ENTER_FRAME, render);
		}
		
		protected function buildSkeleton():void{
			skeleton3D = new Skeleton3D();
			world.addChild(skeleton3D);
		}
		
		override protected function update(skeleton:Skeleton):void{
			skeleton3D.skeleton = skeleton;
			skeleton3D.update();
		}
		
		private function render(evt:Event):void{
			camera.view.render();
			camera2.view.render();
		}
	}
}